import { Component, Injector, OnInit } from '@angular/core';
import { SFUISchema } from '@delon/form';
import { STComponentBase } from '@shared/itcore/components/st-component-base';
import { AjaxResult } from '@shared/itcore/itcore.model';
import { ItcoreSTColumn } from '@shared/itcore/services/alain.types';
import { itcoreService } from '@shared/itcore/services/itcore.service';

@Component({
    selector: 'app-security-tool',
    templateUrl: './tool.component.html',
    styleUrls: ['./tool.component.less'],
    styles: [
        ` 
        `
    ],
})
export class SecurityToolComponent implements OnInit {

    itcore: itcoreService;
    constructor(injector: Injector) {
        this.itcore = injector.get(itcoreService);
    }

    leftValue: string;
    rightValue: string;
    ngOnInit() {

    }
    // 解密
    decryptHandle() {
        if (!this.rightValue) {
            this.itcore.msgSrv.error('密文不能为空！');
            return;
        }
        this.itcore.http.post('api/SecurityTool/decrypt', [{ Id: '0', Ciphertext: this.rightValue, Plaintext: '' }]).subscribe((res) => {
            if (res.Type === 200) {
                this.leftValue = res.Data[0].Plaintext;
            } else {
                this.itcore.msgSrv.error(res.Content);
            }
        });
    }
    // 加密
    encryptHandle() {
        if (!this.leftValue) {
            this.itcore.msgSrv.error('加密明文不能为空！');
            return;
        }
        this.itcore.http.post('api/SecurityTool/encrypt', [{ Id: '0', Ciphertext: '', Plaintext: this.leftValue }]).subscribe((res) => {
            if (res.Type === 200) {
                this.rightValue = res.Data[0].Ciphertext;
            } else {
                this.itcore.msgSrv.error(res.Content);
            }
        });
    }
}
